function handle_tables() {
    if (!jQuery().dataTable) {
        return;
    }

    $('#container_table').dataTable({
        "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "_MENU_ records per page",
            "oPaginate": {
                "sPrevious": "Prev",
                "sNext": "Next"
            }
        },
        "aoColumnDefs": [{
            'bSortable': false,
            'aTargets': [0]
        }]
    });
}



function handle_image_management() {
    $(".delete_button").click(function () {
        var current_td = $(this).parent().parent();
        var image_name = current_td.find(".image_name").html();
        image_name = image_name.substr(0, image_name.indexOf(":"));
        $.ajax({
            url: "/docker/image/delete/" + image_name,
            type: "GET",
            dataType: "json",
            success: function () {
                current_td.remove();
                notification_area.removeClass("hidden");
                notification_area.html(
                    '<button class="close" data-dismiss="alert">×</button> \
                    Image <strong>' + image_name + '</strong> has been deleted.'
                    );
            }
        });
    });
}



$(document).ready(function () {
    handle_tables();
    handle_image_management();
});